package cn.swing.learning;

import cn.linpq.event.MineLabelMouseListenter;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

/**
 * Desc : TODO
 * ClassName : cn.swing.learning.MineLabelMouseListener
 *
 * @author : 林鹏群
 * @date : 2022/12/22 14:37
 */
public class MineLabelMouseListener extends MouseAdapter {
    private MineFrame mineFrame;

    private boolean first = true;

    public MineLabelMouseListener(MineFrame mineFrame) {
        this.mineFrame = mineFrame;
    }
    @Override
    public void mousePressed(MouseEvent e) {
        MineLabel mineLabel =  (MineLabel)e.getSource();

        if (e.getModifiers()== 16){
            if (first){
                first = false;
                mineFrame.getMineField().buildMine();
            }
            if(mineLabel.isBlank()==false){
                mineLabel.setIcon(Tools.arrounMines[0]);
            }
            System.out.println("左键按下");
        }else if(e.getModifiers() == 4){
            System.out.println("右键按下");
        }




    }
    @Override
    public void mouseReleased(MouseEvent e) {
//        mineFrame.getMineField().openAll();
        MineLabel mineLabel =  (MineLabel)e.getSource();

        if (e.getModifiers()== 16){
            mineFrame.getMineField().openMine(mineLabel);
            mineFrame.getMineField().win();
            System.out.println("左键");
        }else if(e.getModifiers() == 4){
            System.out.println("右键");
        }
    }
}
